//
//  NaviBottomView.m
//  one_buy_guizhou_ios
//
//  Created by xu yao on 2021/2/2.
//  Copyright © 2021 杨帅. All rights reserved.
//

#import "NaviBottomView.h"
#import "UIView+Extension.h"
#import "CSButton.h"

@interface NaviBottomView ()

@end

@implementation NaviBottomView

+ (instancetype)naviBottomView{
    NaviBottomView *nbv = [[NaviBottomView alloc] initWithFrame:CGRectMake(0, 10, [UIScreen mainScreen].bounds.size.width, 108)];
    
    return nbv;
}

- (instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        self.backgroundColor = [UIColor whiteColor];
        [self setupUI];
    }
    return self;
}

- (void)setupUI {
    [self addSubview:self.phoneIView];
    [self addSubview:self.nameLabel];
    [self addSubview:self.addressLabel];
    [self addSubview:self.detailButton];
    [self addSubview:self.closeButton];
    [self addSubview:self.sliderarriveView];
}

- (void)layoutSubviews{
    [super layoutSubviews];
    [self.phoneIView sizeToFit];
    self.phoneIView.origin = CGPointMake(12, 12);
    
    [self.detailButton sizeToFit];
    self.detailButton.centerY = self.phoneIView.centerY;
    self.detailButton.right = self.width - 12;
    
    [self.nameLabel sizeToFit];
    self.nameLabel.centerY = self.phoneIView.centerY;
    self.nameLabel.left = self.phoneIView.right + 4;
    
    [self.addressLabel sizeToFit];
    self.addressLabel.width = self.detailButton.left - self.nameLabel.right - 20 - 10;
    self.addressLabel.centerY = self.nameLabel.centerY;
    self.addressLabel.left = self.nameLabel.right + 20;
    
    [self.closeButton sizeToFit];
    self.closeButton.left = self.phoneIView.left;
    self.closeButton.top = self.phoneIView.bottom + 24;
    
    self.sliderarriveView.right = self.width - 12;
    self.sliderarriveView.centerY = self.closeButton.centerY;
}

- (void)setOrderId:(NSString *)orderId {
    _orderId = orderId;
    self.sliderarriveView.orderId = orderId;
}

- (void)setWaybillNo:(NSString *)waybillNo {
    _waybillNo = waybillNo;
    self.sliderarriveView.waybillNo = waybillNo;
}

- (void)setWaybillStatus:(int)waybillStatus {
    _waybillStatus = waybillStatus;
    self.sliderarriveView.waybillStatus = waybillStatus;
}

- (void)onPhone {
    if (!self.phoneString.length) {
        return;
    }
    NSString *callPhone = [NSString stringWithFormat:@"telprompt://%@", self.phoneString];
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:callPhone]];
}

#pragma mark 懒加载
- (UIImageView *)phoneIView {
    if (!_phoneIView) {
        _phoneIView = [[UIImageView alloc] init];
        _phoneIView.image = [UIImage imageNamed:@"icon／路线备份 7"];
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onPhone)];
        [_phoneIView addGestureRecognizer:tap];
        _phoneIView.userInteractionEnabled = YES;
    }
    return _phoneIView;
}

- (UILabel *)nameLabel {
    if (!_nameLabel) {
        _nameLabel = [[UILabel alloc] init];
        _nameLabel.text = @"颜瑶";
        _nameLabel.textColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.85];
        _nameLabel.font = [UIFont systemFontOfSize:16];
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onPhone)];
        [_nameLabel addGestureRecognizer:tap];
        _nameLabel.userInteractionEnabled = YES;
    }
    return _nameLabel;
}

- (UILabel *)addressLabel {
    if (!_addressLabel) {
        _addressLabel = [[UILabel alloc] init];
        _addressLabel.text = @"贵州省贵阳市观山湖区长岭南路天一国际广场国家大数据处理中心";
        _addressLabel.textColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.45];
        _addressLabel.font = [UIFont systemFontOfSize:12];
    }
    return _addressLabel;
}

- (UIButton *)detailButton {
    if (!_detailButton) {
        _detailButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [_detailButton setTitle:@"详情 〉" forState:UIControlStateNormal];
        [_detailButton setTitleColor:[UIColor colorWithRed:0 green:0 blue:0 alpha:0.45] forState:UIControlStateNormal];
        _detailButton.titleLabel.font = [UIFont systemFontOfSize:12];
        
    }
    return _detailButton;
}

- (CSButton *)closeButton{
    if (!_closeButton) {
        _closeButton = [CSButton buttonWithType:UIButtonTypeCustom];
        [_closeButton setTitle:@"退出" forState:UIControlStateNormal];
        _closeButton.titleLabel.font = [UIFont systemFontOfSize:15];
        [_closeButton setTitleColor:[UIColor colorWithRed:0 green:0 blue:0 alpha:0.85] forState:UIControlStateNormal];
        [_closeButton setImage:[UIImage imageNamed:@"icon／路线备份 2"] forState:UIControlStateNormal];
    }
    return _closeButton;
}

@end
